/*canvas绘制*/
var img=document.createElement("img");                  //用制作好的图片创建img对象
img.src="images/frame.png";


var entities_QH =[];                                    //片区标签
unitsBillboardShow(regions, entities_QH);               //初始化打开


var entities_GW =[];                                    //单元标签
var entities_QW =[];
var entities_MW =[];
var entities_DCW = [];
var entities_BAZX = [];
var buildingsBillboards = [];


/*canvas绘制方法*/

function drawCanvas(img,text,fontsize,tx,ty){
    var canvas = document.createElement('canvas');      //创建canvas标签
    var ctx = canvas.getContext('2d');

    ctx.fillStyle = '#99f';
    ctx.font = fontsize + "px Arial";
    
    canvas.width = 140;      
    canvas.height = 56; 

    ctx.drawImage(img, 0,0,140,56);

    ctx.fillStyle = '#fff';
    ctx.font = fontsize + "px Calibri,sans-serif";
    ctx.shadowOffsetX = 1;                              //阴影往左边偏，横向位移量
    ctx.shadowOffsetY = 0;                              //阴影往左边偏，纵向位移量
    //ctx.shadowColor = "#fff";                         //阴影颜色
    ctx.shadowBlur = 1;                                 //阴影的模糊范围
    ctx.textAlign = "center";
    ctx.fillText(text, tx, ty);
    return canvas;
};

function unitsBillboardShow(units, list){
    for(i=0;i<units.length;i++){
        let unit = units[i];
        list[i]=viewer.entities.add({
            id:unit.id,
            position: Cesium.Cartesian3.fromDegrees(unit.X,unit.Y,400),
            billboard:{
                image: drawCanvas(img,unit.name,unit.fontsize,70,35),
                scaleByDistance:new Cesium.NearFarScalar(1000, 1, 100000,0.1),                  //设置随图缩放距离和比例
                distanceDisplayCondition:new Cesium.DistanceDisplayCondition(50, 100000)        //设置可见距离
            }
        })
    }
};

function unitsBillboardClose(list){
    for(i=0;i<list.length;i++){
        viewer.entities.removeById(list[i].id)
    }
}